<template>
  <div class="main">
    <div class="content">
      <div class="top">
        <div class="box">
          <div class="left">客户姓名</div>
          <input type="text" v-model="name" class="text_input">
        </div>
        <div class="box">
          <div class="left">联系电话</div>
          <input type="text" v-model="phone" class="text_input notselect">
        </div>
        <div class="box">
          <div class="left">订单号</div>
          <input type="text" v-model="shopId" readonly class="text_input">
        </div>
        <div class="box">
          <div class="left">条形码</div>
          <input type="text" v-model="barCode" readonly class="text_input">
        </div>
        <div class="box">
          <div class="left">商品问题</div>
          <input type="text" v-model="reason" class="text_input">
        </div>
      </div>
      <div class="middle">
        <div>
          <input type="radio" id="one" value="0" v-model="picked">
          <label for="one">厂家维修</label>
        </div>
        <div>
          <input type="radio" id="two" value="1" v-model="picked">
          <label for="two">第三方维修</label>
        </div>
      </div>
      <div class="bottom">
        <div class="button" @click="confirm" id="confirm">提交申请</div>
      </div>
    </div>
  </div>
</template>

<script>
    import salesPersonService from "../../service/aftersales";

    export default {
      name: "RepairTheMachine",
      data () {
        return {
          name: null,
          phone: null,
          shopId: null,
          barCode: null,
          reason: null,
          picked: ''
        }
      },
      mounted() {
        this.shopId = this.$route.params.shopId
        this.barCode = this.$route.params.barCode
      },
      methods: {
        async confirm() {
          if (this.shopId==null||this.barCode==null) {
            alert("刷新页面失去数据")
            this.$router.push({name:'BeforeSales'})
            return
          }
          if (this.name==null||this.phone==null||this.reason==null||this.picked=="") {
            alert("请填写完整")
            return
          }
          const loginedUser = this.$store.getters.getLoginUser
          if (loginedUser == null) {
            return
          }
          const data = {
            serviceId: loginedUser.storeId,
            shopId: this.shopId,
            customer: this.name,
            barCode: this.barCode,
            phone: this.phone,
            problem: this.reason,
            repairType: this.picked
          }
          let result = await salesPersonService.repairgoods(data)
          if (result.data.code == 2000)
            alert(result.data.data)
          else{
            console.log(result.data)
            alert(result.data.data)
          }
          this.$router.push({name:'BeforeSales'})
        }
      }
    }
</script>

<style lang="scss" scoped>
  input::-webkit-outer-spin-button,
  input::-webkit-inner-spin-button {
    -webkit-appearance: none;
  }
  input[type="number"]{
    -moz-appearance: textfield;
  }
  .main {
    width: 100%;
    height: calc(100% - 1px);
    background: #FFFFFF;
    border-top: 1px solid transparent;
  .content {
    width: 406px;
    left: 128px;
    margin: 0 auto;
  .top {
    width: 100%;
  .box {
    width: 100%;
    height: 25px;
    margin-top: 10px;
  .left {
    height: 25px;
    line-height: 25px;
    width: 106px;
    float: left;
    text-align: left;
    font-size: 14px;
  }
  .text_input {
    border-width: 1px;
    width: 298px;
    height: 23px;
  }
  .notselect {
    cursor: default;
  }
  }
  }
    .middle {
      width: 100%;
      margin: 10px auto;
      height: 20px;
      display: flex;
      justify-content: space-between;
    }
  .bottom {
    width: 100%;
  .button {
    margin: 20px auto;
    width: 284px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 13px;
    border-radius: 10px;
    border: 1px solid black;
  }
  .button:hover {
    background: #c1e8ff;
    cursor: pointer;
  }
  }
  }
  }
</style>
